<?php

require "include/bittorrent.php";
dbconn();
loggedinorreturn();
checkserver();

if (get_user_class() < $staffmem_class) {
	stderr("错误", "权限不足");
}
$username = $CURUSER['username'];
$noticeoff = $_POST['noticeoff'] == '' || $_POST['noticeoff'] == 'yes' ? "yes" : "no";
$notice = $_POST['notice'];
if ($notice == '') {
	stderr("错误", "内容不可为空！");
}
$data = date("Y-m-d H:i:s", TIMENOW);
$count = mysql_num_rows(sql_query("SELECT id FROM notice ORDER BY id DESC LIMIT 1"));
if ($count == 0) {
	sql_query("INSERT notice (noticeoff, notice, bydata, byuser) VALUES ('$noticeoff', '$notice', '$data', '$username')");
} else {
	sql_query("UPDATE notice SET noticeoff = '$noticeoff', notice = '$notice', bydata = '$data', byuser = '$username' ORDER BY id DESC LIMIT 1");
}
write_log("管理员 $username 修改了小公告");
header("Location: " . get_protocol_prefix() . "$BASEURL/notice.php");
